<template>
  <div>
    <van-nav-bar
      title="添加地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      :area-list="areaList"
      show-postal
      show-set-default
      @save="onSave"
    />
  </div>
</template>

<script>
import { AddressEdit, NavBar, Toast } from 'vant'
import areaList from '@/components/area'

export default {
  components: {
    [AddressEdit.name]: AddressEdit,
    [NavBar.name]: NavBar
  },
  data () {
    return {
      areaList
      // addressinfo: { name: '', tel: '135' },
      // searchResult: [{ name: '黄龙万科中心', address: '杭州市西湖区' }]
    }
  },
  methods: {
    onClickLeft () {
      this.$router.go(-1)
    },
    async onSave (item) {
      console.log(item)
      const params = {
        receiver_name: item.name,
        receiver_phone: item.tel,
        area: item.areaCode,
        detail_address: item.addressDetail,
        zip_code: item.postalCode,
        default_address: item.isDefault
      }
      const { data } = await this.$api.account.addressCreate(params)
      if (data.code !== 200) {
        Toast(data.desc)
      } else {
        Toast(data.desc)
        this.$router.go(-1)
      }
    },
    // async addArea () {
    //   const { data } = await this.$api.account.areaCreate({ areas: areaList })
    //   Toast(data.desc)
    // },
    onChangeDetail () {
    }
  }
}
</script>

<style>
</style>
